package com.yaodian100.ec.member.web;

import java.math.BigDecimal;

import org.apache.commons.lang.xwork.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.ec.member.entity.WishList;
import com.yaodian100.ec.member.service.MemberService;

public class WishListAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -356049920662986284L;
	/** logger */
	private final Logger logger = LoggerFactory.getLogger(WishListAction.class);

	private MemberService memberService;

	private String memberId;
	private String productId;
	private String categoryId;
	private String productName;
	private String fullUrl;
	private String addResonType;
	private String isPriceNotify;
	private String isRestockNotify;
	private String lowerPriceNotify;
	private String memo;

	public String getAddResonType() {
		return addResonType;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public String getFullUrl() {
		return fullUrl;
	}

	public String getIsPriceNotify() {
		return isPriceNotify;
	}

	public String getIsRestockNotify() {
		return isRestockNotify;
	}

	public String getLowerPriceNotify() {
		return lowerPriceNotify;
	}

	public String getMemberId() {
		return memberId;
	}

	public String getMemo() {
		return memo;
	}

	public String getProductId() {
		return productId;
	}

	public String getProductName() {
		return productName;
	}

	
	public void prepare() throws Exception {
		clearErrorsAndMessages();
		logger.info("prepare ok");
	}

	/**
	 * 新增追蹤商品清單
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String save() throws CoreException {
		WishList wishList = new WishList();
		wishList.setProductId(productId);
		wishList.setAddResonType(addResonType);
		wishList.setCategoryId(Long.getLong(categoryId));
		wishList.setFullUrl(fullUrl);
		wishList.setIsPriceNotify(isPriceNotify);
		wishList.setIsRestockNotify(isRestockNotify);
		wishList.setLowerPriceNotify(new BigDecimal(lowerPriceNotify));
		wishList.setMemo(memo);
		if (StringUtils.isNotBlank(memberId))
			wishList = memberService.saveWishList(wishList);
		return "list";
	}

	/**
	 * 查詢追蹤商品清單
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String search() throws CoreException {
		/*
		 * logger.info("memberId : {} ", memberId); CommonCriteria crit = new CommonCriteria(); if
		 * (StringUtils.isNotBlank(memberId)) { crit.addEq("memberId", Long.parseLong(memberId)); wishLists =
		 * wishListService.getList(0, -1, crit, null); logger.info("wishLists:{} ", wishLists); }
		 */
		return "list";
	}

	public void setAddResonType(String addResonType) {
		this.addResonType = addResonType;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public void setFullUrl(String fullUrl) {
		this.fullUrl = fullUrl;
	}

	public void setIsPriceNotify(String isPriceNotify) {
		this.isPriceNotify = isPriceNotify;
	}

	public void setIsRestockNotify(String isRestockNotify) {
		this.isRestockNotify = isRestockNotify;
	}

	public void setLowerPriceNotify(String lowerPriceNotify) {
		this.lowerPriceNotify = lowerPriceNotify;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}
}